#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1100;
int a[maxn];
int sump[maxn]={0};
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		scanf("%d %d",&n,&m);
		for(int i = 1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+1,a+n+1);
		sump[0] = 0;
		for(int i = 1;i<=n;i++) sump[i] = sump[i-1]+a[i];
		int minc = 110,mins = 110;
		for(int i = 1;i<=n-m+1;i++)
		{
			int sp = sump[i+m-1]-sump[i-1];
			int sc = a[i+m-1]-a[i];
		//	printf("%d %d\n",a[i+m-1],a[i]);
			if(sc<minc)
			{
				mins = sp;
				minc = sc;
			}
			else if(sc==minc&&sp<mins) minc=sc;
		}
		printf("%d %d\n",minc,mins);
	}
}
